package com.lyz.apidemo;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @ClassName Test9
 * @Description Arrays
 * @Author 2214361854
 * @Date 2022/2/20 18:33
 * @Version 1.0
 */
public class Test9 {
    public static void main(String[] args) {
        int[] arr ={10,40,23,15,64,13};
        Integer[] arr2 ={10,40,23,15,64,13};
        //返回数组内容
        System.out.println(Arrays.toString(arr));

        //排序升序
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        //二分查找，必须先排序
        System.out.println(Arrays.binarySearch(arr, 23));
        //返回不存在元素的（规律：应该插入的位置索引+1）
        System.out.println(Arrays.binarySearch(arr, 20));

        Arrays.sort(arr2, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return -(o1 - o2);
            }
        });
        System.out.println(Arrays.toString(arr2));
    }
}
